import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/services.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
//import 'package:kzcity_picker/kzcity_picker.dart';
import 'package:magic_car/UI/webview.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:city_pickers/city_pickers.dart';

import 'dart:io';

class ApplyPage extends StatefulWidget {
  ApplyPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<ApplyPage> {
  TextEditingController _nametroller = new TextEditingController();
  TextEditingController _addresstroller = new TextEditingController();
  TextEditingController _mobiletroller = new TextEditingController();
  TextEditingController _contactmantroller = new TextEditingController();
  TextEditingController _contactmobtroller = new TextEditingController();
  // TextEditingController _validtroller = new TextEditingController();
  // TextEditingController _idcardtroller = new TextEditingController();
  // TextEditingController _expricetroller = new TextEditingController();
  TextEditingController _passtroller = new TextEditingController();
  TextEditingController _confirmpasstroller = new TextEditingController();
  List formList;
  bool agreen = false;
  File _image;
  String card_z = '';
  String card_f = '';
  bool select_img = false;
  List license = [];
  String areaStr = '省份/县市/区域';

  String provinceId = '';
  String provinceName = '';
  String cityName = '';
  String cityId = '';
  String areaName = '';
  String areaId = '';
  String role_name = "车商";
  bool isagent = false;

  String fee = "0.00";
String desc = "";
  initState() {
    super.initState();
    formList = [
      {
        "title": '客户姓名',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001云A00001云A00',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
    loadfeeinfo();
  }
  //加载信息
  loadfeeinfo (){
//API_BusinessInfo
Map<String, String> map = new Map();
//map['id']=this.uid;
 HttpHelper.post(HttpHelper.API_BussinessFee, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
           var info = data["info"];
           //reflect(info["license"]).type.reflectedType.toString();
          setState(() {
            // orderInfo=data["data"];
           fee = info["fee"].toString();
           desc = info["desc"];
            
          });
        }
      }
    }, params: map);
  }


  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    var name = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text:isagent?"姓名": '公司名称',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                      controller: _nametroller,
                      decoration: InputDecoration(
                        hintText:isagent?'请输入经纪人姓名' :'请输入公司名称',
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                      ),
                      onChanged: (val) {
                        print(val);
                      },
                    )),
                flex: 2,
              )
            ],
          ),
        ));
    var age = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '详细地址',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _addresstroller,
                        decoration: InputDecoration(
                          hintText: '请输入公司地址',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var tel = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '登录账号',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _mobiletroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: '填写手机号码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var contactman = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '公司负责人',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _contactmantroller,
                        decoration: InputDecoration(
                          hintText: '请输入公司负责人',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var contactmobile = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '联系电话',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _contactmobtroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: '请输入联系电话',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var city = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: new GestureDetector(
            onTap: () async {
              FocusScope.of(context).requestFocus(FocusNode());
              //  final result =
              //                     await KzcityPicker.showPicker(context);

              //                 if (result != null) {
              //                   setState(() {
              //                      provinceName = result.province;
              //                     provinceId = result.provinceCode.toString();
              //                     cityName = result.city;
              //                     cityId = result.cityCode.toString();
              //                     areaName = result.area;
              //                     areaId = result.areaCode.toString();
              //                     setState(() {
              //                       areaStr =
              //                           provinceName + cityName + areaName;
              //                     });
              //                     // provincename = result.province;
              //                     // cityname = result.city;
              //                     // areaname = result.area;

              //                     // areaStr = "${result.city}/${result.area}";
              //                     // data["value"] = areaStr;
              //                   });
              //                 }
              Result result = await CityPickers.showCityPicker(
                  context: context,
                  cancelWidget:
                      Text('取消', style: TextStyle(color: Colors.black54)),
                  confirmWidget:
                      Text("确定", style: TextStyle(color: Colors.blue)));
              print(result);
              if (result != null) {
                setState(() {
                  provinceName = result.provinceName;
                  provinceId = result.provinceId.toString();
                  cityName = result.cityName;
                  cityId = result.cityId.toString();
                  areaName = result.areaName;
                  areaId = result.areaId.toString();

                  areaStr =
                      "${result.provinceName}/${result.cityName}/${result.areaName}";
                  // this.area =
                  //     "${result.provinceName}/${result.cityName}/${result.areaName}";
                });
              }
            },
            child: Container(
              color: Colors.white,
              height: 50,
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                      child: RichText(
                        text: TextSpan(
                            text: '地区选择',
                            style: TextStyle(
                                fontSize: 15,
                                color: Color.fromRGBO(102, 102, 102, 1)),
                            children: [
                              TextSpan(
                                  text: '*',
                                  style: TextStyle(
                                      fontSize: 14, color: Colors.red))
                            ]),
                      ),
                    ),
                    flex: 1,
                  ),
                  Expanded(
                    child: new Padding(
                        padding: new EdgeInsets.fromLTRB(25, 0, 10, 0),
                        child: new GestureDetector(child: new Text(areaStr))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('城市'))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('区/县'))),
                    flex: 2,
                  )
                ],
              ),
            )));
    var valid = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '验证码',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        // controller: _validtroller,
                        decoration: InputDecoration(
                      hintText: '验证码',
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                    ))),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: Align(
                      alignment: Alignment.centerRight,
                      child: new Container(
                        child: new Material(
                          //INK可以实现装饰容器
                          child: new Ink(
                            //用ink圆角矩形
                            // color: Colors.red,
                            decoration: new BoxDecoration(
                              //背景
                              color: Colors.white,
                              //设置四周圆角 角度
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.0)),
                              //设��四周边框
                              border: new Border.all(
                                  width: 1,
                                  color: Color.fromRGBO(27, 182, 251, 1)),
                            ),
                            child: new InkWell(
                                //圆角设置,给水波纹也设置同样的圆角
                                //如果这里不设置就会出现矩形的水波纹效果
                                borderRadius: new BorderRadius.circular(15.0),
                                //设置点击事件回调
                                onTap: () {
                                  sendcode();
                                },
                                child: Container(
                                  //设置 child 居中
                                  alignment: Alignment(0, 0),
                                  height: 35,
                                  width: 105,
                                  child: Text(
                                    "获取验证码",
                                    style: TextStyle(
                                        color: Color.fromRGBO(27, 182, 251, 1)),
                                  ),
                                )),
                          ),
                        ),
                      )
                      // child: new RaisedButton(
                      //   child: Text('申请补考'),
                      //   onPressed: () {},
                      // ),
                      ),
                  // child: new RaisedButton(
                  //   onPressed: () {
                  //     sendcode();
                  //   },
                  //   child: Text('获取验证码'),
                  // ),
                ),
                flex: 1,
              )
            ],
          ),
        ));
    var code = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '身份证号',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        // controller: _idcardtroller,
                        decoration: InputDecoration(
                      hintText: '请输入身份证号',
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                    ))),
                flex: 2,
              )
            ],
          ),
        ));
    var cardimg = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text:isagent?'身份证照片': '营业执照照片',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 12, color: Colors.red))
                        ]),
                  ),
                ),
              ),
              // Expanded(
              //   child: new Padding(
              //       padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
              //       child: new TextField(

              //           decoration: InputDecoration(
              //             hintText: '请输入身份证号',
              //         border: OutlineInputBorder(
              //          borderSide: BorderSide.none,
              //         ),
              //       ))),
              //   flex: 2,
              // )
            ],
          ),
        ));

    var cardimg1 = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 100,
          child: new Row(
            children: <Widget>[
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                        onTap: () {
                          getImage(1);
                        },
                        child: 
                         card_z==""?
                              Image.asset('resource/images/user/upimg.png'):
                              CachedNetworkImage(
                              imageUrl:card_z,
                              width: 100,height: 100,

                            ),)
                        // FadeInImage.assetNetwork(
                        //   placeholder: "resource/images/user/upimg.png",
                        //   image: card_z,
                        // )),
                    // new Image.asset('resource/images/user/card_img1.png'),
                  ),
                  flex: 1),
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                        onTap: () {
                          getImage(2);
                        },
                        child:
                              card_f==""?
                              Image.asset('resource/images/user/upimg.png'):
                              CachedNetworkImage(
                              imageUrl:card_f,
                              width: 100,height: 100,

                            
                          //   FadeInImage.assetNetwork(
                          // placeholder: "resource/images/user/upimg.png",
                          // image: card_f,
                        )),
                    // new Image.asset('resource/images/user/card_img2.png'),
                  ),
                  flex: 1),
            ],
          ),
        ));
    var experice = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '相关工作经历',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(102, 102, 102, 1)))
                        ]),
                  ),
                ),
              ),
            ],
          ),
        ));
    var expericetext = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 150,
          child: new Column(
            children: <Widget>[
              new Padding(
                padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                child: TextField(
                  maxLines: 5,
                  // controller: _expricetroller,
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      fillColor: Color.fromRGBO(238, 238, 238, 1),
                      filled: true,
                      labelText: '输入工作经历'),
                ),
              ),
            ],
          ),
        ));
    var pass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '登录密码',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _passtroller,
                        decoration: InputDecoration(
                          hintText: '请输入登录密码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var confirmpass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '再次确认',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _confirmpasstroller,
                        decoration: InputDecoration(
                          hintText: '请输入密码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var agreen = Padding(
        padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
        child: Container(
            height: 40,
            color: Colors.white,
            child: Row(
              // crossAxisAlignment: CrossAxisAlignment.baseline,
              children: <Widget>[
                // Expanded(
                //   flex: 1,
                //   child:
                Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 0, 0),
                    child: Container(
                      color: Colors.white,
                      alignment: new FractionalOffset(0.0, 0.0),
                      width: 20,
                      height: 20,
                      child: Checkbox(
                        activeColor: Color.fromRGBO(27, 182, 251, 1),
                        checkColor: Colors.blue,
                        value: this.agreen,
                        onChanged: (value) {
                          setState(() {
                            this.agreen = value;
                          });
                        },
                      ),
                    )),
                // Expanded(
                //   flex:2,
                //   child:
                Padding(
                    padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                    child: Container(
                        //color: Colors.white,
                        child: GestureDetector(
                      onTap: () {
                        Navigator.of(context)
                            .push(new MaterialPageRoute(builder: (_) {
                          return new AgreementPage();
                        }));
                      },
                      child: RichText(
                        text: TextSpan(
                            text: '我已经阅读并同意',
                            style: TextStyle(
                                fontSize: 12,
                                color: Color.fromRGBO(51, 51, 51, 1)),
                            children: [
                              TextSpan(
                                  text: '【车魔估检测师入职协议】',
                                  style: TextStyle(
                                    fontSize: 12,
                                    color: Color.fromRGBO(255, 204, 48, 1),
                                  ))
                            ]),
                      ),
                    )))
                //)
              ],
            )));
    var btn = Padding(
      padding: new EdgeInsets.fromLTRB(10, 10, 10, 40),
      child: new SizedBox(
          width: double.infinity,
          height: 45,
          child: new RaisedButton(
            child: Text('立即申请入驻'),
            textColor: Colors.white,
            color: Color.fromRGBO(27, 182, 251, 1),
            onPressed: () {
              regist();
            },
          )),
    );
    tiles.add(checkBoxs());
    tiles.add(name);

    tiles.add(tel);
    if(isagent==false){
    tiles.add(contactman);
    }
    tiles.add(contactmobile);
    tiles.add(city);
    tiles.add(age);
    // tiles.add(valid);
    // tiles.add(code);
    tiles.add(cardimg);
    tiles.add(cardimg1);
    // tiles.add(experice);
    // tiles.add(expericetext);
    tiles.add(pass);
    tiles.add(confirmpass);
    tiles.add(agreen);
    //tiles.add(btn);
    // for (var item in formList) {
    //   tiles.add(Padding(
    //       padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
    //       child: Container(
    //           color: Colors.white,
    //           height: 50,
    //           child: new Row(
    //             children: <Widget>[
    //               Expanded(
    //                 child: new Padding(
    //                     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
    //                     child: new Text(
    //                       item['title'],
    //                       style: TextStyle(fontSize: 15,color: Color.fromRGBO(102, 102, 102, 1)),
    //                     )),
    //                 flex: 1,
    //               ),
    //               new Padding(
    //                   padding: new EdgeInsets.fromLTRB(0, 0, 10, 0),
    //                   child: new Text(
    //                     item['sub_title'],
    //                     style:
    //                         TextStyle(fontSize: 15, color: item['sub_color']),
    //                   )),
    //             ],
    //           ))));
    // }
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  Widget checkBoxs() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 1),
        child: new Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                  color: Colors.white,
                  height: 50,
                  child: new Row(children: <Widget>[
                    Expanded(
                      child: new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                        child: RichText(
                          text: TextSpan(
                              text: '车商类型',
                              style: TextStyle(
                                  fontSize: 15,
                                  color: Color.fromRGBO(102, 102, 102, 1)),
                              children: [
                                // TextSpan(
                                //     text: '*',
                                //     style: TextStyle(fontSize: 14, color: Colors.red))
                              ]),
                        ),
                      ),
                      flex: 1,
                    ),
                    Expanded(
                      child: new Padding(
                          padding: new EdgeInsets.fromLTRB(10, 0, 20, 0),
                          child: Align(
                            alignment: Alignment.centerRight,
                            child: RichText(
                              text: TextSpan(
                                  text: role_name,
                                  style: TextStyle(
                                      fontSize: 15,
                                      color: Color.fromRGBO(102, 102, 102, 1)),
                                  children: [
                                    // TextSpan(
                                    //     text: '*',
                                    //     style: TextStyle(fontSize: 14, color: Colors.red))
                                  ]),
                            ),
                          )),
                      flex: 1,
                    ),
                  ])),
              checkBox()
            ]));
    return content;
  }

  Widget checkBox() {
    List<Widget> tiles = [];
    Widget content;

    List<String> items = ['车商', '经纪人'];
    print('----');

    String defaultv = items[0];
    // if(this.type==2){
    // if (select == false) {
    //   if (item.containsKey("value") == false) {
    //     item['value'] = defaultv;
    //   }
    // }
    //}//车商设置选项默认值
    for (var i = 0; i < items.length; i++) {
      tiles.add(Container(
          child: Wrap(children: <Widget>[
        Padding(
            padding: new EdgeInsets.fromLTRB(10, 0, 0, 0),
            child: SizedBox(
                width: 22,
                child: Radio<String>(
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                    //当前Radio的值
                    hoverColor: Color.fromRGBO(200, 200, 200, 1),
                    focusColor: Color.fromRGBO(25, 172, 249, 1),
                    value: items[i],
                    activeColor: Color.fromRGBO(25, 172, 249, 1),
                    groupValue: role_name,

                    // groupValue: defaultv,
                    onChanged: (value) {
                      if (value == "经纪人") {
                        setState(() {
                          isagent = true;
                        });
                      } else {
                        setState(() {
                          isagent = false;
                        });
                      }
                      setState(() {
                        //  select = true;
                        // defaultv = value;
                        role_name = value;
                      });
                    }))),

        // tiles.add(
        new GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              if (items[i] == "经纪人") {
                setState(() {
                  isagent = true;
                });
              } else {
                setState(() {
                  isagent = false;
                });
              }
              setState(() {
                role_name = items[i];
              });
            },
            child: Padding(
                padding: new EdgeInsets.fromLTRB(8, 12, 15, 0),
                child: Text(items[i],
                    style: new TextStyle(
                        fontSize: 11,
                        color: Color.fromRGBO(100, 100, 100, 1)))))
      ])));
    }
    content = new Wrap(spacing: 0, runSpacing: 0, children: tiles);
    //content = new Row(children: tiles);

    return content;
  }

//注册
  void regist() async {
    FocusScope.of(context).requestFocus(FocusNode());
    var toastmsg = "";
    if (_nametroller.text.trim().length == 0) {
      toastmsg = '请填写姓名';
    } else if (_addresstroller.text.trim().length == 0) {
      toastmsg = '请填写详细地址';
    } else if (_mobiletroller.text.trim().length == 0) {
      toastmsg = '请填写电话号码';
    }
    // else if (_validtroller.text.trim().length == 0) {
    //   toastmsg = '请填写验证码';
    // }
    else if (_contactmobtroller.text.trim().length == 0) {
      toastmsg = '请填写联系电话';
    } else if (_passtroller.text.trim().length == 0) {
      toastmsg = '请填写登录密码';
    } else if (_confirmpasstroller.text.trim().length == 0) {
      toastmsg = '请填写密码';
    } else if (agreen == false) {
      toastmsg = '请勾选入职协议';
    } else if (provinceId == "" || cityId == "" || areaId == "") {
      toastmsg = '请选择区域';
    }
    else if (_contactmantroller.text.trim().length == 0) {
      if(isagent==false)
      toastmsg = '请填写负责人';
      else toastmsg = "";
    } 

    if (toastmsg != "") {
      Toast.show(toastmsg, context);
      return;
    }
    String image_Str = "";
    for (var i = 0; i < license.length; i++) {
      var item = license[i];
      // if(item.containsKey('attachment')){
      if (i == license.length - 1) {
        image_Str = image_Str + item;
      } else
        image_Str = image_Str + item + ',';
    }
    //}
    if (image_Str == "") {
      //请上传图片
      Toast.show('请上传图片', context);
      return;
    }

    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    // map["code"] = _validtroller.text.trim();
    map["name"] = _nametroller.text.trim();
    map["address"] = _addresstroller.text.trim();
    map["contact_people"] = _contactmantroller.text.trim();
    map["contact_mobile"] = _contactmobtroller.text.trim();
    map["password"] = _passtroller.text.trim();
    map["img"] = image_Str;

    map['provinceId'] = provinceId;
    map['provinceName'] = provinceName;
    map['cityName'] = cityName;

    map['cityId'] = cityId;
    map['areaName'] = areaName;
    map['areaId'] = areaId;

    if(isagent){
      map['isagent']="1";
    }
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["id"] = pref.getString('uid');
    // map["idcardback"] = card_f;
    // map["idcardfront"] = card_z;
    print(map);

    HttpHelper.post(HttpHelper.API_RegBussiness, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          Navigator.pop(context);

          setState(() {
            // orderInfo=data["data"];
          });
        }
      }
    }, params: map);
  }

//发送验证码
  sendcode() {
    print('获取验证码');
    if (_mobiletroller.text.trim().length == 0) {
      Toast.show("填写手机号", context);
      return;
    }
    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    HttpHelper.post(HttpHelper.API_SendCode, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "0") {
          // Navigator.pop(context);

          setState(() {
            // orderInfo=data["data"];
          });
        }
      }
    }, params: map);
  }

  //选择图片
  getimgs(type, card) async {
    if (type == 1) {
      var image = await ImagePicker.pickImage(source: ImageSource.gallery);

      setState(() {
        _image = image;
        select_img = true;
      });
    } else {
      var image = await ImagePicker.pickImage(source: ImageSource.camera);

      setState(() {
        _image = image;
        select_img = true;
      });
    }
    if (_image == null) return;
    //File _files = await FlutterNativeImage.compressImage(_image.path,quality: 10,targetWidth: 600,targetHeight: 600);
    Map<String, String> map = new Map();

    HttpHelper.upLoadImage(_image, (data) {
      license.add(data['attachment']);
      if (card == 1) {
        setState(() {
          card_z = data["url"];
        });
      } else {
        setState(() {
          card_f = data["url"];
        });
      }
    }, params: map);
  }

//选择图片方���
  Future getImage(type) async {
    FocusScope.of(context).requestFocus(FocusNode());
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return new SimpleDialog(
            title: new Text('选择'),
            children: <Widget>[
              new SimpleDialogOption(
                child: new Text('相机'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(0, type);
                },
              ),
              new SimpleDialogOption(
                child: new Text('相册'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(1, type);
                },
              )
            ],
          );
        });
    // var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    // //_upLoadImage(image);//上传图片
    // setState(() {
    //   _image = image;
    // });
  }

  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text('申请开通',style: TextStyle(color:Colors.black),),
          backgroundColor: Colors.white,
          elevation: 0,
           iconTheme: IconThemeData(
            color: Colors.black, //修改颜色
          ),
          // backgroundColor: Color.fromRGBO(255, 204, 48, 1),
        ),
        body: new Center(
            child: Container(
                decoration: new BoxDecoration(
                  color: Color.fromRGBO(238, 238, 238, 1),
                ),
                child: Padding(
                    padding: new EdgeInsets.fromLTRB(0, 15, 0, 0),
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                            top: 0,
                            bottom: 80,
                            left: 0,
                            right: 0,
                            child: Align(
                              alignment: Alignment.topCenter,
                              child: new ListView(
                                  children: <Widget>[buildcontent()]),
                            )),
                       isagent? 
                        Align(
                            alignment: Alignment.bottomCenter,
                            child: SizedBox(
                              width: double.infinity,
                              height: 70,
                              child:
                               new Container(
                                color: Colors.white,
                                child: Padding(
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: <Widget>[
                                 
                                      new Container(
                                        child: new Material(
                                          //INK可以实现装饰容器
                                          child: new Ink(
                                            //用ink圆角矩形
                                            // color: Colors.red,
                                            decoration: new BoxDecoration(
                                              //背景
                                              color: Color.fromRGBO(
                                                  255, 204, 48, 1),
                                              //设置四周圆角 角度
                                              borderRadius: BorderRadius.all(
                                                  Radius.circular(18.0)),
                                              //设置四周边框
                                              border: new Border.all(
                                                  width: 1,
                                                  color: Color.fromRGBO(
                                                      255, 204, 48, 1)),
                                            ),
                                            child: new InkWell(
                                                //圆角设置,给水波纹也设置同样的圆角
                                                //如果这里不设置就会出现矩形的水波纹效果
                                                borderRadius:
                                                    new BorderRadius.circular(
                                                        15.0),
                                                //设置点击事件回调
                                                onTap: () {
                                                  regist();
                                                },
                                                child: Container(
                                                  //设置 child 居中
                                                  alignment: Alignment(0, 0),
                                                  height: 36,
                                                  width: 225,
                                                  child: Text(
                                                    "申    请",
                                                    style: TextStyle(
                                                        color: Colors.white),
                                                  ),
                                                )),
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                  padding:
                                      new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                ),
                              ),
                            )):
                       Align(
                            alignment: Alignment.bottomCenter,
                            child: SizedBox(
                              width: double.infinity,
                              height: 70,
                              child:
                               new Container(
                                color: Colors.white,
                                child: Padding(
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.end,
                                    children: <Widget>[
                                  isagent?new Container(height:0):    Expanded(
                                          child: new Column(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.spaceEvenly,
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: <Widget>[
                                            RichText(
                                              text: TextSpan(
                                                  text: '预付服务费 ¥ ',
                                                  style: TextStyle(
                                                      fontSize: 12,
                                                      color: Color.fromRGBO(
                                                          102, 102, 102, 1)),
                                                  children: [
                                                    TextSpan(
                                                        text: fee,
                                                        style: TextStyle(
                                                            fontSize: 12,
                                                            color: Colors.red))
                                                  ]),
                                            ),
                                            Text(
                                              desc,
                                              style: TextStyle(
                                                  color: Color.fromRGBO(
                                                      255, 204, 48, 1),
                                                  fontSize: 9),
                                            )
                                          ])),
                                      new Container(
                                        child: new Material(
                                          //INK可以实现装饰容器
                                          child: new Ink(
                                            //用ink圆角矩形
                                            // color: Colors.red,
                                            decoration: new BoxDecoration(
                                              //背景
                                              color: Color.fromRGBO(
                                                  255, 204, 48, 1),
                                              //设置四周圆角 角度
                                              borderRadius: BorderRadius.all(
                                                  Radius.circular(18.0)),
                                              //设置四周边框
                                              border: new Border.all(
                                                  width: 1,
                                                  color: Color.fromRGBO(
                                                      255, 204, 48, 1)),
                                            ),
                                            child: new InkWell(
                                                //圆角设置,给水波纹也设置同样的圆角
                                                //如果这里不设置就会出现矩形的水波纹效果
                                                borderRadius:
                                                    new BorderRadius.circular(
                                                        15.0),
                                                //设置点击事件回调
                                                onTap: () {
                                                  regist();
                                                },
                                                child: Container(
                                                  //设置 child 居中
                                                  alignment: Alignment(0, 0),
                                                  height: 36,
                                                  width: 125,
                                                  child: Text(
                                                    "申    请",
                                                    style: TextStyle(
                                                        color: Colors.white),
                                                  ),
                                                )),
                                          ),
                                        ),
                                      )
                                    ],
                                  ),
                                  padding:
                                      new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                ),
                              ),
                            ))
                      ],
                    )
                    // new ListView(
                    //   children: <Widget>[buildcontent()],
                    // )),
                    ))));
  }
}
